import { BasicColumn, BasicTable, FormSchema, useTable } from "@/components/Table";
import { copyApi } from "@/api/bpm/task/copy/index";
import { formatDate } from "@/utils/util";
import { Button } from "antd";
import HandlingProcess from "../todo/components/handlingProcess";
import { useDrawer } from "@/components/Drawer";
import { useTranslation } from "react-i18next";
const index = () => {
	const { t } = useTranslation();
	const en_vi = "task.copy";
	const columns: BasicColumn[] = [
		{
			title: t(`${en_vi}.processName`),
			dataIndex: "processInstanceName"
		},
		{
			title: t(`${en_vi}.promoter`),
			render: (_, record) => record.startUser.nickname
		},
		{
			title: t(`${en_vi}.initiationTime`),
			dataIndex: "processInstanceStartTime",
			render: (time: any) => formatDate(new Date(time))
		},
		{
			title: t(`${en_vi}.CCNode`),
			dataIndex: "activityName"
		},
		{
			title: t(`${en_vi}.ccTo`),
			render: (_, record) => record.createUser.nickname
		},
		{
			title: t(`${en_vi}.comments`),
			dataIndex: "reason"
		},
		{
			title: t(`${en_vi}.ccTime`),
			dataIndex: "createTime",
			render: (time: any) => formatDate(new Date(time))
		},
		{
			title: t(`${en_vi}.operate`),
			fixed: "right",
			width: 200,
			render: (_, record) => {
				return (
					<div>
						<Button type="link" onClick={handle(record)}>
							{t(`${en_vi}.details`)}
						</Button>
					</div>
				);
			}
		}
	];
	const schemas: FormSchema[] = [
		{
			field: "processInstanceName",
			label: t(`${en_vi}.processName`),
			component: "Input"
		},
		{
			field: "createTime",
			label: t(`${en_vi}.ccTime`),
			component: "RangePicker"
		}
	];
	const [registerTable] = useTable({
		api: copyApi.processInstanceCopyPage,
		columns,
		useSearchForm: true,
		formConfig: {
			labelWidth: 100,
			schemas,
			showActionButtonGroup: true,
			baseColProps: { span: 6 },
			actionColOptions: { span: 24 }
		},
		bordered: true
	});
	const [registerDrawer, { openDrawer }] = useDrawer();
	const handle = (record: any) => () => {
		openDrawer(true, {
			record,
			page: "copy"
		});
	};
	return (
		<div>
			<BasicTable register={registerTable}></BasicTable>
			<HandlingProcess register={registerDrawer}></HandlingProcess>
		</div>
	);
};
export default index;
